package com.summer.bilibili.validator.datetime;

import cn.hutool.core.date.DateField;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * 验证日期/时间字段是否满足特定时间范围要求
 */
@Documented
@Constraint(validatedBy = { DateTimeLimitValidator.class }) //声明验证逻辑实现类为 DateTimeLimitValidator
@Target({ METHOD , FIELD , ANNOTATION_TYPE , CONSTRUCTOR , PARAMETER , TYPE_USE })
@Retention(RUNTIME)
@Repeatable(DateTimeLimit.List.class)
public @interface DateTimeLimit {
    // 验证方向：过去/未来
    public enum Type {
        PAST, FUTURE
    }

    Type type ();

    // 时间偏移量
    int offset () default 0;

    String timezone () default "GMT+8";

    DateField unit () default DateField.SECOND;

    // 非法值
    String message () default "时间不在允许的范围内";


    Class < ? >[] groups () default {};

    Class < ? extends Payload >[] payload () default {};

    @Target({ METHOD , FIELD , ANNOTATION_TYPE , CONSTRUCTOR , PARAMETER , TYPE_USE })
    @Retention(RUNTIME)
    @Documented
    @interface List {
        DateTimeLimit[] value ();
    }
}
